//
//  CashierStockPopView.m
//  TryShopping
//
//  Created by LiYinDi on 16/6/17.
//  Copyright © 2016年 RuiBen. All rights reserved.
//

#import "CashierStockPopView.h"
#import "UIButton+UIButtonImageAndText.h"
@interface CashierStockPopView()
{
    
   
    UIButton *alphaBtn;
    UIView *bottomView;
    UILabel *leftLineLabel;
    UILabel *rightLineLabel;
    UILabel *tagLabel;
    
    UIButton *whsInButton;
    UIButton *whsOutButton;
    UIButton *checkButton;
    UIButton *needOrderButton;
    
}
@end
@implementation CashierStockPopView
-(instancetype)init
{
    self=[super init];
    if (self) {
        [self createUI];
        [self setAutoLayout];
    }
    return self;
}
-(void)createUI
{
    alphaBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [alphaBtn setBackgroundColor:[UIColor clearColor]];
    [alphaBtn addTarget:self action:@selector(alphaBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:alphaBtn];
    
    bottomView =[[UIView alloc] init];
    [bottomView setBackgroundColor:[UIColor whiteColor]];
    [self addSubview:bottomView];
    
    leftLineLabel=[[UILabel alloc] init];
    [leftLineLabel setBackgroundColor:[UIColor colorWithRed:238.0f/255.0f green:238.0f/255.0f blue:238.0f/255.0f alpha:1.0]];
    [bottomView addSubview:leftLineLabel];
    
    tagLabel=[[UILabel alloc] init];
    tagLabel.text=@"提交到";
    tagLabel.textAlignment=NSTextAlignmentCenter;
    tagLabel.font=[UIFont systemFontOfSize:13];
    [tagLabel setTextColor:[UIColor colorWithRed:153.0f/255.0f green:153.0f/255.0f blue:153.0f/255.0f alpha:1.0]];
    [bottomView addSubview:tagLabel];
    
    rightLineLabel=[[UILabel alloc] init];
    [rightLineLabel setBackgroundColor:[UIColor colorWithRed:238.0f/255.0f green:238.0f/255.0f blue:238.0f/255.0f alpha:1.0]];
    [bottomView addSubview:rightLineLabel];
    
    whsInButton=[UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *whsInImg=[UIImage imageNamed:@"shangpinruku"];
    UIImage *whsInTinted = [whsInImg rt_tintedImageWithColor:[UIColor colorWithRed:90.0/255.0 green:130.0/255.0 blue:26.0/255.0 alpha:1.0] ];
    [whsInButton setImage:whsInTinted withTitle:@"入库" forState:UIControlStateNormal];
    [whsInButton setTitleColor:[UIColor colorWithRed: 204.0/255.0f green:204.0/255.0f blue:204.0/255.0f alpha:1.0] forState:UIControlStateNormal];
    [whsInButton addTarget:self action:@selector(whsInButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:whsInButton];
    
    whsOutButton=[UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *whsOutImg=[UIImage imageNamed:@"shangpinchuku"];
    UIImage *whsOutTinted = [whsOutImg rt_tintedImageWithColor:[UIColor colorWithRed:90.0/255.0 green:130.0/255.0 blue:26.0/255.0 alpha:1.0] ];
    [whsOutButton setImage:whsOutTinted withTitle:@"出库" forState:UIControlStateNormal];
    [whsOutButton setTitleColor:[UIColor colorWithRed: 204.0/255.0f green:204.0/255.0f blue:204.0/255.0f alpha:1.0] forState:UIControlStateNormal];
    [whsOutButton addTarget:self action:@selector(whsOutButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:whsOutButton];
    
    checkButton=[UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *checkImg=[UIImage imageNamed:@"kucunpandian"];
    UIImage *checkTinted = [checkImg rt_tintedImageWithColor:[UIColor colorWithRed:90.0/255.0 green:130.0/255.0 blue:26.0/255.0 alpha:1.0] ];
    [checkButton setImage:checkTinted withTitle:@"盘点" forState:UIControlStateNormal];
    [checkButton setTitleColor:[UIColor colorWithRed: 204.0/255.0f green:204.0/255.0f blue:204.0/255.0f alpha:1.0] forState:UIControlStateNormal];
    [checkButton addTarget:self action:@selector(checkButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:checkButton];

    
    needOrderButton=[UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *needOrderImg=[UIImage imageNamed:@"shangpinruku"];
    UIImage *needOrderTinted = [needOrderImg rt_tintedImageWithColor:[UIColor colorWithRed:90.0/255.0 green:130.0/255.0 blue:26.0/255.0 alpha:1.0] ];
    [needOrderButton setImage:needOrderTinted withTitle:@"要货" forState:UIControlStateNormal];
    [needOrderButton setTitleColor:[UIColor colorWithRed: 204.0/255.0f green:204.0/255.0f blue:204.0/255.0f alpha:1.0] forState:UIControlStateNormal];
    [needOrderButton addTarget:self action:@selector(needOrderButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:needOrderButton];
}
-(void)whsInButtonClick
{
    
    if ([self.delegate respondsToSelector:@selector(whsInBtnClick)]) {
        [self.delegate whsInBtnClick];
    }
    [self removeFromSuperview];

}
-(void)whsOutButtonClick
{
    if ([self.delegate respondsToSelector:@selector(whsOutBtnClick)]) {
        [self.delegate whsOutBtnClick];
    }
    [self removeFromSuperview];
}
-(void)checkButtonClick
{
    if ([self.delegate respondsToSelector:@selector(checkBtnClick)]) {
        [self.delegate checkBtnClick];
    }
    [self removeFromSuperview];
}
-(void)needOrderButtonClick
{
    if ([self.delegate respondsToSelector:@selector(needOrderBtnClick)]) {
        [self.delegate needOrderBtnClick];
    }
    [self removeFromSuperview];
}
-(void)alphaBtnClick
{
    [self removeFromSuperview];
}
- (void)show
{
    // 获得主窗口
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    self.frame= CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [window addSubview:self];
    
    
}

-(void)setAutoLayout
{
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.bottom.equalTo(self.mas_bottom);
        make.height.equalTo(@190);
    }];
    [leftLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bottomView.mas_left).with.offset(10);
        make.right.equalTo(tagLabel.mas_left);
        make.top.equalTo(bottomView.mas_top).with.offset(38);
        make.height.equalTo(@1);
        
    }];
    [tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.width.equalTo(@55);
        make.height.equalTo(@15);
        make.centerY.equalTo(leftLineLabel.mas_centerY);
         make.centerX.equalTo(bottomView.mas_centerX);
    }];
    [rightLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bottomView.mas_right).with.offset(-10);
        make.top.equalTo(leftLineLabel.mas_top);
        make.height.equalTo(@1);
        make.left.equalTo(tagLabel.mas_right);
    }];
    
    [whsInButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bottomView.mas_left);
        make.width.equalTo(bottomView.mas_width).dividedBy(4);
        make.top.equalTo(leftLineLabel.mas_bottom);
        make.bottom.equalTo(bottomView.mas_bottom);
    }];
    [whsOutButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(whsInButton.mas_right);
        make.width.equalTo(bottomView.mas_width).dividedBy(4);
        make.top.equalTo(leftLineLabel.mas_bottom);
        make.bottom.equalTo(bottomView.mas_bottom);
    }];
    [checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(whsOutButton.mas_right);
        make.width.equalTo(bottomView.mas_width).dividedBy(4);
        make.top.equalTo(rightLineLabel.mas_bottom);
        make.bottom.equalTo(bottomView.mas_bottom);
    }];
    [needOrderButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(checkButton.mas_right);
        make.width.equalTo(bottomView.mas_width).dividedBy(4);
        make.top.equalTo(rightLineLabel.mas_bottom);
        make.bottom.equalTo(bottomView.mas_bottom);
    }];


    [alphaBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.bottom.equalTo(bottomView.mas_top);
        make.top.equalTo(self.mas_top);
    }];

}
@end
